<?php  
class Model_Site extends Model{ 

    //首页数据
    public function getSitePost($offset=0,$pageSize=20){

        $data=DB::select(array('postid','id'),'title','introduction','description','tags','images','url','price','view','reach','review','created','wish','praiseup','praisedown')
        
        ->from('post')
        
        ->where('isdeleted','=','0')

        ->order_by('sort','desc')
        
        ->order_by('praiseup','desc')

        ->order_by('view','desc')

        ->order_by('wish','desc')

        ->order_by('postid','desc')
        
        ->limit($pageSize)
        
        ->offset($offset)
        
        ->execute()->as_array();

        return $data;

    }

    //最新数据
    public function getNewInfo($offset=0,$pageSize=20){

        $data=DB::select(array('postid','id'),'title','introduction','description','tags','images','url','price','view','reach','review','created','wish','praiseup')
        
        ->from('post')
        
        ->where('isdeleted','=','0')
        
        ->order_by('postid','desc')
        
        ->limit($pageSize)
        
        ->offset($offset)
        
        ->execute()->as_array();

        return $data;
    }

    //post总数
    public function getItems(){

         $total= DB::select(array(DB::expr('count(1)'), 'total'))

         ->from('post')

        ->where('isdeleted','=','0')

        ->execute()

        ->get("total");

        return $total;

    }

    //热门
    public function getHotPost($offset=0,$pageSize=20){

        $data=DB::select(array('postid','id'),'title','introduction','description','tags','images','url','price','view','reach','review','created','wish','praiseup','praisedown')
        
        ->from('post')
        
        ->where('isdeleted','=','0')
        
        ->order_by('view','desc')

        ->order_by('praiseup','desc')

        ->order_by('wish','desc')

        ->order_by('postid','desc')
        
        ->limit($pageSize)
        
        ->offset($offset)
        
        ->execute()->as_array();

        return $data;
    }

}
